package com.gxar.quick.ar.server.base.model.material.mapper;

import com.gxar.quick.ar.server.base.model.material.vo.request.AdminUpdateMaterialRequest;
import com.gxar.quick.ar.server.base.model.material.vo.request.AdminUploadMaterialRequest;
import com.gxar.quick.ar.server.base.model.material.vo.response.AdminMaterialDetailResponse;
import com.gxar.quick.ar.server.base.model.material.vo.response.AdminMaterialPageListResponse;
import com.gxar.quick.ar.server.base.model.material.vo.response.AdminUpdateMaterialResponse;
import com.gxar.quick.ar.server.base.model.material.vo.response.AdminUploadMaterialResponse;
import com.gxar.quick.ar.server.db.model.MaterialsEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author linsy
 * @version 1.0
 * @created 2023/11/9 17:25
 */
@Mapper
public interface MaterialMapStruct {

    MaterialMapStruct INSTANCE = Mappers.getMapper(MaterialMapStruct.class);


    /**
     * 实体转分页响应
     *
     * @param entity 实体
     * @return 分页响应
     */
    @Mapping(target = "id", expression = "java(String.valueOf(entity.getId()))")
    AdminMaterialPageListResponse entityToPageResponse(MaterialsEntity entity);

    List<AdminMaterialPageListResponse> entitiesToPageResponse(List<MaterialsEntity> materialsEntities);

    /**
     * 上传请求转实体
     *
     * @param request 请求
     * @return 实体
     */
    MaterialsEntity uploadToEntity(AdminUploadMaterialRequest request);

    /**
     * 实体转上传响应
     *
     * @param entity 实体
     * @return 上传响应
     */
    @Mapping(target = "id", expression = "java(String.valueOf(entity.getId()))")
    AdminUploadMaterialResponse materialToUpload(MaterialsEntity entity);

    /**
     * 更新请求转实体
     *
     * @param request 请求
     * @return 实体
     */
    MaterialsEntity updateToEntity(AdminUpdateMaterialRequest request);

    /**
     * 实体转更新响应
     *
     * @param entity 实体
     * @return 更新响应
     */
    @Mapping(target = "id", expression = "java(String.valueOf(entity.getId()))")
    AdminUpdateMaterialResponse materialToUpdate(MaterialsEntity entity);

    /**
     * 实体转素材详情
     *
     * @param entity 实体
     * @return 素材详情
     */
    @Mapping(target = "id", expression = "java(String.valueOf(entity.getId()))")
    AdminMaterialDetailResponse materialToDetail(MaterialsEntity entity);
}
